package  
{
  import mge.graph.Graph;
  import mge.graph.Node;
	/**
   * ...
   * @author ivan
   */
  public class AddNodeCommand implements Command
  {
    
    public function AddNodeCommand(graphStage:GraphStage, node:Node) 
    {
      this.graphStage = graphStage;
      this.node = node;
      visualNode = new VisualNode(node);
      redo();
    }
    
    public function undo():void
    {
      // Removes from graph.
      /*
      var index:int = graphStage.graph.nodes.indexOf(node);
      if (index != -1)
        graphStage.graph.nodes.splice(index, 1);
        */
      // Finds and remove visual node.
      for (var i:int = 0; i < graphStage.numChildren; i++)
      {
        var vn:VisualNode = graphStage.getChildAt(i) as VisualNode;
        if (vn && vn.node === node)
        {
          graphStage.removeChildAt(i);
          break;
        }
      }
    }
    
    public function redo():void
    {
      // graphStage.graph.nodes.push(node);
      graphStage.addChild(visualNode);
    }
    
    private var graphStage:GraphStage;
    private var node:Node;
    private var visualNode:VisualNode;
    
  }

}